# Maintainer : Laurent Carlier <lordheavym@gmail.com>
# Maintainer : Daenyth <Daenyth+Arch _AT_ gmail _DOT_ com>
# Contributor : wizzomafizzo <wizzomafizzo@gmail.com>
# Contributor: tochiro@no.spam.mail.berlios.de
# Contributor: sh__

pkgname=uqm
pkgver=0.8.0
pkgrel=3
pkgdesc="The Ur-Quan Masters, a port of Star Control 2"
arch=('loong64' 'x86_64')
url="http://sc2.sourceforge.net/"
license=('GPL')
depends=('libmikmod' 'libvorbis' 'sdl_image' 'libgl' 'glu')
makedepends=('imagemagick' 'mesa' 'namcap')
source=(https://downloads.sourceforge.net/sourceforge/sc2/uqm-${pkgver}-src.tgz
        https://downloads.sourceforge.net/sourceforge/sc2/uqm-${pkgver}-content.uqm
        config.state
        uqm
        uqm.desktop
        uqm.png)
noextract=(uqm-${pkgver}-content.uqm)
sha256sums=('24f2f7db9cf7faf53b95f9e2580e6f596205a98ed0c335cfe834c64785ad4f5a'
            '77d75ac25e6fb755a33c4ba3b38a7b7bc41fcbc02896891b0cc9ac9214b72eef'
            'fa079bd198f0d392627e28f52e2ab9a8230c533fe9db8c4648369a6b346f0223'
            '9e986584c69a40116a11b68de3c5b781f4698b7106ae9091a35bef3072520d28'
            '42e6d6cf33e5129cd194a7e70b66fa23c276e3ebaef06b3dbbae2ef319ab74d3'
            'd0bc1c3c1a8582060edc40c24d638313f8b3c76cf723a540f971c47127d3a4c8')

prepare() {
  cd $pkgname-$pkgver
  cp ../config.state .
  sed -e "/INPUT_install_prefix/ s|replaceme|$pkgdir/usr|" \
      -i config.state    
  ./build.sh uqm reprocess_config

  # fix build (Fedora)
  cd src/uqm/comm/
  for d in */ ; do
    cd $d
    mv strings.h ustrings.h
    cd ..
  done
  find . -type f -name '*.c' | xargs sed -i s/strings.h/ustrings.h/g
  find . -type f -name '*.h' | xargs sed -i s/STRINGS/USTRINGS/g
}

build() {
  cd $pkgname-$pkgver
  ./build.sh uqm
}
  
package() {
  cd $pkgname-$pkgver
  ./build.sh uqm install

  install -Dm644 "$srcdir"/$pkgname-$pkgver-content.uqm \
     "$pkgdir"/usr/share/uqm/content/packages/$pkgname-$pkgver-content.uqm

  # stolen from fedora!
  install -Dm644 "$srcdir"/uqm.desktop \
     "$pkgdir"/usr/share/applications/uqm.desktop
  install -Dm644 "$srcdir"/uqm.png \
     "$pkgdir"/usr/share/pixmaps/uqm.png

  rm "$pkgdir"/usr/bin/uqm
  install -Dm755 "$srcdir"/uqm "$pkgdir"/usr/bin/uqm
}
